<?php
	class Application
	{
		protected $_controller;
		protected $_action;
		protected $_query;
		
		function __construct()
		{
			if(isset($_REQUEST['load']))
			{
				$params = explode("/", $_GET['load']);
				$this->setController(ucwords($params[0]));
				if (isset($params[1]) && !empty($params[1]))
				{
					$this->setAction($params[1]);
				}
				
				if (isset($params[2]) && !empty($params[2]))
				{
					$this->setQuery($params[2]);
				}
			}
			else
			{
				$this->setController('Home');
				$this->setAction('index');
				$this->setQuery(null);
			}
		}
		
		function setController($controller)
		{
			$this->_controller=$controller;
		}
		
		function getController()
		{
			return $this->_controller;
		}
		
		function setAction($action)
		{
			$this->_action=$action;
		}
		
		function getAction()
		{
			return $this->_action;
		}
		
		function setQuery($query)
		{
			$this->_query=$query;
		}
		
		function getQuery()
		{
			return $this->_query;
		}
		
		public function run()
		{
			$modelName = $this->getController();
			$controller = $modelName.'Controller';
			$layout='twocolumn';
			$load = new $controller($modelName, $this->getAction(),$layout);
			if (method_exists($load, $this->getAction()))
			{
				$load->{$this->getAction()}($this->_query);
			}
			else 
			{
				die('Invalid method. Please check the URL.');
			}
		}
	}
?>